import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
    	orderdata:[],
    	ordernum:0,
		justprice:0,
    	totalprice:0,
    	discount:0,
		totalcount:0,
    	paidprice:0,
		allgoods:[],
		orderid:'',
		shownumarr:[1,2,3],
		showhongbao:'',
		hongbaonum:0,
		hongbaototal:0,
		whethershowhongbao:false,
		whethershowhongbao2:false,
		whethershowhongbao3:false,
		doubleused:false,
		showotherhongbao:false,
		otherhongbaotext:'惊喜',
		doubleuseded:false,
		jingxiused:false,
		doublenumused:false,
		doublefirst:'',
		doublenumuseded:false,
		personnum:'请选择'
    },
    mutations:{
		addhongbao:function(state,data){
			if(typeof(data)=='object'){
				state.showhongbao=data[0],
				state.whethershowhongbao=true
				setTimeout(function(){
				state.whethershowhongbao2=true
				state.whethershowhongbao3=true
				},100)
				state.showsecond=data[1]
			}
			else{
			state.showhongbao=data
			state.whethershowhongbao=true
			setTimeout(function(){
				state.whethershowhongbao2=true
				state.whethershowhongbao3=true
			},100)
			}
		},
		getjustprice:function(state,data){
			state.justprice=data
		},
		getdoublefirst:function(state,data){
			state.doublefirst=data
		},
		getnumarr:function(state,data){
			state.shownumarr=data
		},
		getpersonnum:function(state,data){
			state.personnum=data
		},
		gethongbaototal:function(state,data){
			state.hongbaototal=data
		},
		getotherhongbao:function(state,data){
			state.showotherhongbao=true;
			state.otherhongbaotext=data
		},
		getjingxiused:function(state,data){
			state.jingxiused=true
		},
		overjingxiused:function(state,data){
			state.jingxiused=false
		},
		getdoubleused:function(state,data){
			state.doubleused=true
		},
		getdoubleuseded:function(state,data){
			state.doubleuseded=true
		},
		overdoubleuseded:function(state,data){
			state.doublenumuseded=false
		},
		getdoublenumused:function(state,data){
			state.doublenumused=true
		},
		getdoublenumuseded:function(state,data){
			state.doublenumuseded=true
		},
		overdoublenumuseded:function(state,data){
			state.doubleuseded=false
		},
		stophongbao:function(state,data){
			state.whethershowhongbao=false
			state.whethershowhongbao2=false
			state.showotherhongbao=false
			if(state.showsecond){
				state.showhongbao=state.showsecond,
				state.whethershowhongbao=true
				setTimeout(function(){
				state.whethershowhongbao2=true
				state.whethershowhongbao3=true
				},100)
				state.showsecond=0
			}
		},
		gethongbaonum:function(state,data){
			state.hongbaonum=data
		},
		getAllgoods:function(state,data){
			state.allgoods=data;
		},
		getOrderid:function(state,data){
			state.orderid=data
		},
    	pushorder:function(state,word){
    		this.state.orderdata=word
    	},
    	splitorder:function(state,word){
    		state.orderdata.forEach(function(data,index){
    			if(data.taste.toString()==word.taste.toString()){
    				state.orderdata.splice(index,1)
    			}
    		})
    		console.log(state.orderdata)
    	},
    	gettotalprice:function(state,price){
    		state.totalprice=price
    		state.paidprice=state.totalprice-state.discount
		},
		gettotalcount:function(state,num){
			state.totalcount=num;
		},
    	getdiscount:function(state,dis){
    		state.discount=dis
    	},
    	getpaidprice:function(state,money){
    		state.paidprice=money
    	}
    }
})

export default store